#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int countTexts(string pressedKeys) {
        int n = pressedKeys.size();
        const int MOD = 1e9 + 7;
        vector<int> dp(n + 1);
        dp[0] = 1;
        for (int i = 1; i <= n; i++)
        {
            int j = 1;
            int m = pressedKeys[i - 1] == '7' || pressedKeys[i - 1] == '9' ? 3 : 2;
            for (; j <= m && i - j - 1 >= 0 && pressedKeys[i - j - 1] == pressedKeys[i - 1]; ++j)
            {
                dp[i] += dp[i - j];
                dp[i] %= MOD;
            }
            if (i - j >= 0)
            {
                dp[i] += dp[i - j];
                dp[i] %= MOD;
            }

        }
        return dp[n];
    }
};